#!/bin/python


import sys, os, os.path, logging
import logging.handlers
import locale
import gettext

from optparse import OptionParser

import ClientAppFrame
import wtsglobal




if __name__ == "__main__":
    # =============== Home ================
    basedir = os.path.dirname(sys.argv[0])
    if basedir == "":
        basedir = "."
    os.chdir(basedir)
    # =============== Command line parameters ================
    parser = OptionParser()
    parser.add_option("-c", "--config", dest="inifile",
                  help="config file", metavar="FILE")
    parser.add_option("-l", "--log", dest="logfile",
                  help="log file", metavar="FILE")
    (options, args) = parser.parse_args()
    print "~~~~options:",options
    print "~~~~args:",args
    # =============== Logging ================
##    options={"logfile":"wts_zigbee.log","inifile":"wts_zigbee.ini"}
    options.logfile = "wts_zigbee.log"
    options.inifile = "wts_zigbee.ini"
    if not options.logfile:
        options.logfile= 'wts.log'
    logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(levelname)s %(message)s',
                    filename=options.logfile,
                    filemode='a')
    error_filename = options.logfile + ".error"
    error_logFile = logging.handlers.RotatingFileHandler(error_filename,'a',200000,3)
    formatter = logging.Formatter()
    error_logFile.setFormatter(formatter)
    error_logFile.setLevel(logging.ERROR)
    logging.getLogger('').addHandler(error_logFile)                    
    # =============== Locale ================
    localedir = "locale"
    gettext.install('lang', localedir , unicode=True)
    try :
        gettext.translation('lang', localedir, languages=[locale.getdefaultlocale()[0]]).install(True)
    except:
        pass
    # =============== Run me ================
    if not options.inifile:
        options.inifile= 'wts.ini'
    wtsglobal.inifile = options.inifile
    
    appmain=ClientAppFrame.aaaa(1)
